import logging
import threading
import time
from pathlib import Path
import pytest
from tools.ERP上传 import 退货退款上传
from tools.decorators import log_decorator
from DrissionPage import ChromiumPage, ChromiumOptions
from tools.page import page_get
from tools.获取日期 import get_date
from 获取数据.获取售后退货退款 import 获取售后退货退款
from datetime import datetime, timedelta


@pytest.mark.run()
@log_decorator
@pytest.mark.flaky(reruns=2, reruns_delay=3, reruns_show_all=True)
def 售后退货退款_test(login_聚水潭):
    page = page_get()
    page('text=订单').click()
    page('text=售后(退货退款)').click()
    page.wait.ele_displayed('text=组合查询')
    page.wait(10)
    page('#status_Confirmed').click(by_js=True)
    page('#status_waitconfirm').click(by_js=True)
    page('#is_null_l_id').select('否')
    # 定义起始日期和结束日期
    date = get_date('昨天')
    date1 = datetime.strptime(date, '%Y-%m-%d')
    date2 = datetime.strptime(date, '%Y-%m-%d')
    # date1 = datetime.strptime('2024-04-20', '%Y-%m-%d')
    # date2 = datetime.strptime('2024-04-21', '%Y-%m-%d')
    # 定义间隔
    interval = timedelta(days=3)
    # 遍历日期并打印
    date_start = date1
    while date_start <= date2:
        date_end = date_start + interval
        if date_end > date2:
            date_end = date2
        print(date_start.strftime('%Y-%m-%d'), date_end.strftime('%Y-%m-%d'))
        获取售后退货退款(date_start.strftime('%Y-%m-%d'), date_end.strftime('%Y-%m-%d'))
        date_start = date_end + timedelta(days=1)
        if date_end == date2:
            break
        time.sleep(1)


